package com.midea.leetcode;

/**
 * @description：
 * @author: wangwl23
 * @create: 2020-10-12 16:24
 */
public class IndexOf {
    public static void main(String[] args) {

        int i = strStr("a", "a");
        //System.out.println(i);
        String s = "abcdefg";
        String substring = s.substring(4, 8);
        System.out.println(substring);


    }
    public static int strStr(String haystack, String needle) {
        if (needle.length() == 0)return 0;
        if (haystack.length() == 0)return -1;
        int size = needle.length();
        for (int i = 0; i < haystack.length(); i++){
            if (i+size<= haystack.length()) {
                String s = haystack.substring(i, i + size);
                if (needle.equals(s)){
                    return i;
                }
            }
        }
        return -1;
    }
}
